package com.leyou.item.dto;

import com.leyou.dto.BaseDTO;
import com.leyou.entity.BaseEntity;
import lombok.Data;
import lombok.NoArgsConstructor;

import java.util.Collection;
import java.util.Collections;
import java.util.List;
import java.util.stream.Collectors;

@Data
@NoArgsConstructor
public class CategoryDTO extends BaseDTO {

    private long id;//类别id

    private String name;//类别名称

    private long parentId;//父类id，顶级类目填零

    private int isParent;// 是否有父节点，0为否，1为是

    private int sort; //  排序指数，越小越往前排

    public CategoryDTO(BaseEntity entity) {
        super(entity);
    }

    /**
     * 将PO集合转为DTO集合
     * @param list PO对象的集合
     * @param <T> PO的类型
     * @return DTO集合
     */
    public static <T extends BaseEntity> List<CategoryDTO> convertEntityList(Collection<T> list){
        if(list == null){
            return Collections.emptyList();
        }
        return list.stream().map(CategoryDTO::new).collect(Collectors.toList());
    }


}
